package cn.mgr.logistics.adapter;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.mgr.logistics.activity.R;
import cn.mgr.logistics.model.BackTruckInfo;

public class BackTrunkInfoAdapter extends BaseAdapter {
	private Context mContext;
	private LinkedList<BackTruckInfo> dataSource;
	private LayoutInflater mInflater;
	protected int size = 0;

	public BackTrunkInfoAdapter(Context c, LinkedList<BackTruckInfo> dataSource) {
		this.mContext = c;
		this.dataSource = dataSource;
		mInflater = LayoutInflater.from(mContext);
	}

	public Context getmContext() {
		return mContext;
	}

	public void setmContext(Context mContext) {
		this.mContext = mContext;
	}

	public int getCount() {
		if (size != 0)
			return size;
		if (dataSource != null)
			return dataSource.size();
		else
			return 0;
	}

	public Object getItem(int position) {
		return dataSource.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = new ViewHolder();
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.list_items_layout, null);
			holder.explain = (TextView) convertView.findViewById(R.id.content);
			holder.releaseTime = (TextView) convertView.findViewById(R.id.note);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if (dataSource != null && dataSource.size() != 0) {
			holder.explain.setText(dataSource.get(position).getBt_num());
			holder.releaseTime.setText((dataSource.get(position)
					.getBt_createtime()));
		}

		return convertView;

	}

	class ViewHolder {
		TextView explain;
		TextView releaseTime;
	}

	public List<BackTruckInfo> getDataSource() {
		return dataSource;
	}

	public void modifyDataSource(LinkedList<BackTruckInfo> o) {
		dataSource = o;

	}

	/**
	 * add list item
	 * 
	 * @param item
	 */
	public void addItem(BackTruckInfo item) {
		dataSource.add(item);
	}

	public void setSize(int size) {
		this.size = size;
	}

}
